IE582 - Fall2021

HOMEWORK 1

TASK 1

A)

Fractions of points within distance 1

B)

For D=2 The fraction approximates the ratio of the volume of the unit circle to the square inscribing it.

The area of the circle is calculated as:

(Π*r^2)

The area of the square inscribing the circle with r=1 is 4. So;

0.799 = (Π*r^2) / 4 where r=1

Π is approximately calculated as:

For D=3 The fraction approximates the ratio of the volume of the unit sphere to the cube inscribing it.

The volume of the circle is calculated as:

(4/3)Πr^3

The volume of the cube inscribing the sphere with r=1 is 8. So;

0.524 = (4/3)Πr^3 / 8 where r=1

Π is approximately calculated as:

C)

To observe the approximation of Π I will perform the calculations for larger sample sizes for 2 dimensional plane and 3 dimensional space.

For D=2

For D=3

For both D=2 and D=3 as the sample size gets larger approximation of pi gets closer to the actual value. Fluctutations of the approximated values around the real value is expected as a result of randomness.

For D=3 the approximation is very close to the real value when the sample size is 1000.This can also be considered as a result of randomness. As the sample size gets larger approximation shows the expected behavior.

D) NEAREST NEIGHBORS

TASK 2

The image is read with the readJPEG function and stored as my_image. As stated below the object is numeric array, which consists of "doubles", with dimensions 512x512x3. The results are consistent with the information given in the homework description. There are 3 512x512 matrices to represent the color intensity of each pixel for 3 colors RED, GREEN and BLUE.

When matrices representing each channel is displayed the result is a black and white image that only demonstrates the instensity of the colors.

To observe colors I created a matrix of zeros with size 512x512. Then I created 3 arrays with sizes 512x512x3. I assigned each color red, blue and green to the corresponding space of one matrix and filled remaining spaces with the zero matrices.

When I put the related elements of matrices red, blue and green together and discard the zeros I get the original image.

For each channel column means are calculated and plotted as below.

I split the image into two halves and subtracted the right half from the left. The two halves and new image is shown below negative pixel values are set to zero:

Red channel of new image is displayed below:

Green channel of new image is displayed below:

Blue channel of new image is displayed below:

To create a noisy image noise is added to the each pixel of the original image. Noise values are generated from uniform distribution with minimum value of 0 and a maximum value of “0.1 * maximum pixel value observed” to each pixel value for each channel of original image.

Maximum pixel value observed is 1 and there are 47 pixels with value 1.